package cn.ad.server.web.servlet;

import cn.ad.server.common.utils.SpringContextUtils;
import cn.ad.server.web.servlet.v2.RestPathFilter;
import cn.ad.server.web.spring.service.actions.AdTrackingAction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 
 * @deprecated 原广告请求处理Servlet框架将不推荐使用，统一采用v2包下的处理方式，请求入口参考{@link RestPathFilter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)}
 */
@Deprecated
@WebServlet("/click.html")
public class AdClickServlet extends AbstractAdServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = -2391659270221886692L;
	private Logger logger = LoggerFactory.getLogger(AdClickServlet.class);

	public AdTrackingAction getTrackingAction() {
		return SpringContextUtils.getBean(AdTrackingAction.class);
	}

	@Override
	void doService(HttpServletRequest request, HttpServletResponse response) {
		
		
		try {
			request.getRequestDispatcher("/v2/click/ch/1").forward(request, response);
		} catch (ServletException e) {
			logger.error("ServletException", e);
		} catch (IOException e) {
			logger.error("IOException", e);
		}
		return;
		
		
//		ClickPresentation cp = new ClickPresentation();
//		ClickAndImpressionCommand clickCommand = new ClickAndImpressionCommand();
//		try {
//
//			WebUtils.convetGetRequestParam(request, clickCommand);
//
//			if (Exchange.GDT.getValue().equals(clickCommand.getPlatform_id())) {
//				covertGDTParam(clickCommand);
//			}
//
//			String ip = IPUtils.parseIp(request);
//			clickCommand.setIp(ip);
//			clickCommand.setUa(request.getHeader("user-agent"));
//			clickCommand.setHandleType("1");
//			// <<<<<<< HEAD
//
//			getTrackingAction().handleClick(clickCommand, cp);
//
//			// =======
//			//
//			// //logger.info("----- {}", System.currentTimeMillis() - ss);
//			// adService.handleClick(clickCommand,cp);
//			// //logger.info("----- {}", System.currentTimeMillis() - ss);
//			//
//			// >>>>>>> origin/feature-adview
//			if (!StringUtils.isEmpty(clickCommand.getTarget())) {
//				response.setStatus(302);
//				response.setHeader("Location", URLDecoder.decode(clickCommand.getTarget(), "UTF-8"));
//				response.setHeader("Connection", "close");
//			}
//		} catch (Exception e) {
//			logger.error("/click.html error - params : [ {} ],", clickCommand, e.getMessage(), e);
//		} finally {
//			adService.unbond();
//			loggerService.logAdClick(cp);
//		}
	}

}
